package com.lesson60.action;

import com.lesson60.sshdemo.Category;
import com.lesson60.sshdemo.CategoryController;
import com.opensymphony.xwork2.ActionSupport;

public class CategoryAction extends ActionSupport {
	public String categoryname;
	public CategoryController mCategoryController;
	
	public CategoryController getmCategoryController() {
		return mCategoryController;
	}
	public void setmCategoryController(CategoryController mCategoryController) {
		this.mCategoryController = mCategoryController;
	}
	public String getCategoryname() {
		return categoryname;
	}
	public void setCategoryname(String categoryname) {
		this.categoryname = categoryname;
	}
	/**
	 * @return
	 */
	public String execute() {
		if(getCategoryname() != null){
			System.out.println("the category name=" + getCategoryname());
		}
		addCategory();
		getmCategoryController().getAll();
		return SUCCESS;
	}
	
	private void addCategory(){
		Category category = new Category();
		category.setId(1);
		category.setCategoryname(getCategoryname());
		category.setFatherid(0);
		category.setCategorypath(0+ "," + 1);
		category.setDeleteid(0);
		
		System.out.println("the category init finish.");
		getmCategoryController().addCategory(category);
		System.out.println("the category add finish.");
	}
}